﻿using System;
using System.Architecture;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using HDK.UI.Controls;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace HDK.Demo.Pages.Views
{
    [ExportView("ParallaxView", "", new string[] { "MainRegion" })]
    public sealed partial class ParallaxView : UserControl, IView
    {
        static Random R = new Random();

        public ParallaxView()
        {
            this.DataContext = this;
            this.InitializeComponent();

            foreach (UIElement element in parallaxPanel.Children)
            {
                element.SetValue(ParallaxPanel.XProperty, (double)R.Next(-200, 100));
                element.SetValue(ParallaxPanel.YProperty, (double)R.Next(-200, 100));
                element.SetValue(ParallaxPanel.ZProperty, (double)R.Next(0, 150));
            }
        }

        
        private void LayoutRoot_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            //var p = e.GetCurrentPoint(LayoutRoot).RawPosition;
            //double x = -0.5 * ((LayoutRoot.ActualWidth / 2 - p.X) / 2);
            //double y = -0.5 * ((LayoutRoot.ActualHeight / 2 - p.Y) / 2);
            //y = Math.Max(y, -150);
            //x = Math.Max(x, -150);
            //x = Math.Min(x, 150);

            //parallaxPanel.CameraX = x;
            //parallaxPanel.CameraY = y;
        }

        private void LayoutRoot_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            var p = e.Position;

            double x = -0.5 * ((LayoutRoot.ActualWidth / 2 - p.X) / 2);
            double y = -0.5 * ((LayoutRoot.ActualHeight / 2 - p.Y) / 2);
            y = Math.Max(y, -150);
            x = Math.Max(x, -150);
            x = Math.Min(x, 150);

            parallaxPanel.CameraX = x;
            parallaxPanel.CameraY = y;
        }

    }
}
